<?php
/**
 * User: hjd-yao
 * Date: 2019/6/4
 * Time: 14:20
 */

namespace Shop\Http\Controllers;


use App\Helpers\SelfResponse;
use App\Http\Controllers\Controller;
use App\Models\Shop\ShopCategoryModel;
use Frontend\Models\UserBaseModel;
use Illuminate\Http\Request;

class BaseController extends Controller
{

    public function __construct()
    {
        $this->showCate();
        $this->shopNav();
    }



    public function view($view,$data = [], $mergeData = [])
    {
        if(is_mobile()){
            return view('WShop::'.$view,$data, $mergeData);
        }else{
            return view('PShop::'.$view,$data, $mergeData);
        }
    }

    public function wapRender($view,$data = [], $mergeData = [])
    {
        if(request()->ajax()){
            return response()->json(['status'=>1,'data'=>$data]);
        }else{
            return view('WShop::'.$view,$data, $mergeData);
        }
    }

    public function pcRender($view,$data = [], $mergeData = [])
    {
        return view('PShop::'.$view,$data, $mergeData);
    }

    public function perNum($num = 20)
    {
        return $num;
    }

    public function showCate()
    {
        $category = ShopCategoryModel::where('status',1)->select(['id','name','name_mobile','parent_id'])->get()->toArray();
        $category = list_to_tree($category,true,'id','parent_id');

        view()->share('category',$category);
    }

    public function shopNav()
    {
        $category = ShopCategoryModel::where('status',1)->where('parent_id',0)
            ->select(['id','name','name_mobile','parent_id'])->limit(6)->get();

        view()->share('shop_nav',$category);
    }

}